// pages/index/payment/payment.js
import {
  getCaVeueRentalObjPage,getCaItemSalePage,getCaItemRentalPage
} from "../../../api/place.js";
import {
  insertOaShopDetail
} from "../../../api/buy.js";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    date: '',
    show: false,
    datalist: [],
    price: '',
    num:'',
    totalprice:0,
    lostprice:0,
    lostprice1:0,
    titleText:'',
    type:1,
    id:1,
  },
  pay() {
    let data = {
        
      "uaUserId":1,
      "oaShopDetailType":2,
      "oaShopDetailTypeId":null,
      "shopType":this.data.type,//商品类型
      "shopTypeId":this.data.id,//商品id
      "purchasesNum":this.data.num,//购买数量
      "payState":1,
      "orderState":2,
    }
    this.insertOaShopDetail(data);
    wx.navigateTo({
      url: '/pages/index/success/success',
    })
  },
  insertOaShopDetail(data){
    insertOaShopDetail(data).then(res =>{
      console.log('1')
      // this.getCmCommentPage(this.data.postid)
    })
  },
  onDisplay() {
    this.setData({
      show: true
    });
  },
  onClose() {
    this.setData({
      show: false
    });
  },
  formatDate(date) {
    date = new Date(date);
    return `${date.getMonth() + 1}/${date.getDate()}`;
  },
  onConfirm(event) {
    const [start, end] = event.detail;
    this.setData({
      show: false,
      date: `${this.formatDate(start)} - ${this.formatDate(end)}`,
    });
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options.data)
    let data = JSON.parse(options.data);
    let id=data.id;
    let type=data.type
    if(data.type===1)
    this.getCaVeueRentalObjPage(data.id)
    if(data.type===2)
    this.getCaItemRentalPage(data)
    if(data.type===3)
    this.getCaItemSalePage(data)
  },
  getCaItemRentalPage(option) {
    let data = {
      "pageNum": "1",
      "pageSize": "10",
      "id": option.id,
      "caCampId": option.campid,
      "titleText": null,
      "detailText": null,
      "photoUrl": null,
      "price": null,
      "percentage": null,
      "service": null,
      "inventory": null,
      "praiseNum": null,
      "collectionNum": null,
      "status": null,
      "delFlag": null,
      "createBy": null,
      "createTime": null,
      "updateBy": null,
      "updateTime": null,
      "remark": null
    }
    getCaItemRentalPage(data).then(res => {
      let datalist = res.data.data.records;
      let title=datalist[0].caCamp.titleText;
      let titleText=datalist[0].titleText
      console.log(datalist)
      this.setData({
        datalist: datalist,
        title:title,
        titleText:titleText,
        lostprice:datalist[0].price,
        lostprice1:datalist[0].price,
        totalprice:datalist[0].price,
        // num:datalist.length,
      })
    })
  },
  getCaItemSalePage(option) {
    let data = {
      "pageNum": "1",
      "pageSize": "10",
      "id": option.id,
      "caCampId": option.campid,
      "titleText": null,
      "photoUrl": null,
      "price": null,
      "freight": null,
      "service": null,
      "inventory": null,
      "praiseNum": null,
      "collectionNum": null,
      "status": null,
      "delFlag": null,
      "createBy": null,
      "createTime": null,
      "updateBy": null,
      "updateTime": null,
      "remark": null
    }
    getCaItemSalePage(data).then(res => {
      let datalist = res.data.data.records;
      let title=datalist[0].caCamp.titleText;
      let titleText=datalist[0].titleText
      console.log(datalist)
      this.setData({
        datalist: datalist,
        title:title,
        titleText:titleText,
        lostprice:datalist[0].price,
        lostprice1:datalist[0].price,
        totalprice:datalist[0].price,
        // num:datalist.length,
      })
    })
  },
  getCaVeueRentalObjPage(id) {
    let data = {
      "pageNum": "1",
      "pageSize": "10",
      "id": id,
      "caVenueRentalId": null,
      "veueRentalCode": null,
      "photoUrl": null,
      "price": null,
      "inventory": null,
      "transactionNum": null,
      "status": null,
      "delFlag": null,
      "createBy": null,
      "createTime": null,
      "updateBy": null,
      "updateTime": null,
      "remark": null
    }
    getCaVeueRentalObjPage(data).then(res => {
      let datalist = res.data.data.records;
      let titleText = datalist[0].veueRentalCode
      let titele = datalist[0].caVenueRental.title
      // console.log(datalist)
      this.setData({
        datalist: datalist,
        titleText:titleText,

        lostprice:datalist[0].caVenueRental.lostPrice,
        lostprice1:datalist[0].caVenueRental.lostPrice,
        totalprice:datalist[0].caVenueRental.lostPrice,
        num:datalist.length,
      })
    })
  },
 
  onChange(e) {
   let num=e.detail
  //  console.log(this.data.date)
   let price=num*(Number)(this.data.lostprice)
    this.setData({
      lostprice1:price,
      totalprice:price
    })
  },
})